'''
Created on Jul 4, 2012

@author: peng
'''
from datetime import datetime

ONE_DAY_TIME = 60 * 60 * 24


_EPOCH = datetime(1970, 1, 1)


def unix_time():
    td = datetime.utcnow() - _EPOCH
    ts = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 1e6) / 1e6
    return int(ts)


def get_epoch_date(offsize=0):
    td = datetime.utcnow() - _EPOCH
    ts = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 1e6) / 1e6
    v = int(ts - offsize)
    v = int((v / ONE_DAY_TIME) * ONE_DAY_TIME)
    return datetime.utcfromtimestamp(v)

print str(get_epoch_date())

print datetime.now().strftime('%Y/%m/%d/%H')


from time import mktime


def date2UTC(date_string):
    date = datetime.strptime(date_string, "%Y-%m-%d")
    return mktime(date.timetuple()) * 1000

print int(date2UTC('2012-09-04'))
